package org.sang.controller;

import org.sang.bean.RespBean;
import org.sang.bean.Task;
import org.sang.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TaskController {

    @Autowired
    TaskService taskService;


    @RequestMapping(value = "/member/task", method = RequestMethod.POST)
    public RespBean addSalaryCfg(Task task) {
        if (taskService.addTask(task) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @RequestMapping(value = "/member/task", method = RequestMethod.GET)
    public List<Task> getTasks() {
        return taskService.getAll();
    }

    @RequestMapping(value = "/volunteer/task", method = RequestMethod.GET)
    public List<Task> getTasksByVolunteer() {
        return taskService.getAll();
    }

    @RequestMapping(value = "/manager/task", method = RequestMethod.GET)
    public List<Task> getTasksByManager() {
        return taskService.getAll();
    }

    @RequestMapping(value = "/member/task/{taskNo}", method = RequestMethod.DELETE)
    public RespBean deleteSalary(@PathVariable("taskNo") int taskNo) {
        if (taskService.deleteTask(taskNo) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @RequestMapping(value = "/member/task", method = RequestMethod.PUT)
    public RespBean updateTask(Task task) {
        if (taskService.updateTask(task) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @RequestMapping(value = "/volunteer/task", method = RequestMethod.PUT)
    public RespBean updateTime(Task task) {
        if (taskService.updateTaskTime(task) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
}
